package com.appkubes.mall.restful.application.user.collect.service.impl;

import com.appkubes.mall.core.entity.MallUserCollect;
import com.appkubes.mall.core.service.impl.BaseMallUserCollectServiceImpl;
import com.appkubes.mall.restful.application.user.collect.dao.UserCollectDao;
import com.appkubes.mall.restful.application.user.collect.entity.dto.UserCollectUpsertDTO;
import com.appkubes.mall.restful.application.user.collect.entity.vo.UserCollectUpsertVO;
import com.appkubes.mall.restful.application.user.collect.service.UserCollectService;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @Author: Rongjie
 * @Date: 2020/1/12 10:55
 * @Description:
 */
@Service
@Data
public class UserCollectServiceImpl extends BaseMallUserCollectServiceImpl implements UserCollectService {
    @Resource
    UserCollectDao userCollectDao;

    @Override
    @Transactional
    public UserCollectUpsertDTO upsert(UserCollectUpsertVO upsertVO) {
        MallUserCollect userCollect = new MallUserCollect();
        BeanUtils.copyProperties(upsertVO, userCollect);
        userCollect.setAppKey(null);
        this.saveOrUpdate(userCollect);

        UserCollectUpsertDTO collectUpsertDTO = new UserCollectUpsertDTO();
        collectUpsertDTO.setCollectKey(userCollect.getCollectKey());
        return collectUpsertDTO;
    }
}
